<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ include file="/common/taglibs.jsp"%>

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>菜单管理</title>
<link type="text/css" rel="stylesheet"
	href="${ctx }/js/ztree/css/zTreeStyle/zTreeStyle.css" />
<script type="text/javascript" src="${ctx }/js/bootstrap/jquery.js"></script>
<script type="text/javascript">
	$(function() {
		$("#deptForm").validationEngine('attach', {promptPosition : "bottomLeft", scroll:"false"});
	});
	
	var setting = {
			view: {
				showIcon: false
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				onClick: addOrEditMenu
			}
		};

		var zNodes = ${menuTree};
		
		var zTree;
		
		$(document).ready(function(){
			$.fn.zTree.init($("#deptTree"), setting, zNodes);
			zTree = $.fn.zTree.getZTreeObj("deptTree");
		});
	
		
		function addOrEditMenu(event, treeId, treeNode, clickFlag){
			$("#deptView").show();
			
			
			var id  = treeNode.id;
			
			$.ajax({
				url:"${ctx}/menu/getMenuById",
				type:"POST",
				dataType:"text",
				data:"id="+id,
				success:function(data){
					var json = eval("("+data+")");
					$("#id").val(json.id);
					$("#name").val(json.name);
					$("#icon").val(json.icon);
					$("#sort").val(json.sort);
					if(json.permissions!=null){						
						$("#status").val(json.permissions.status);
					}
					
				}
			});			
		}
		
		
		
		
		
		function subForm(){
			if($("#deptForm").validationEngine('validate')){
				$("#deptForm").ajaxSubmit({
			        type: "post",
			        dataType: "text",
			        success: function(data){
			        	if(data == 'true'){
			        		art.dialog({content:"保存成功！",ok:function(){window.location.href="${ctx}/menu/view?menuUrlSign=1";}});
			        	}else{
			        		art.dialog({content:"保存失败！",ok:true});
			        	}
			        }
			    });
			}
		}
		
		
		
</script>
</head>
<body>
	<div class="breadcrumbs" id="breadcrumbs">
		<script type="text/javascript">
        try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
    </script>

		<ul class="breadcrumb">
			<li><i class="ace-icon fa fa-home home-icon"></i> <a
				href="${ctx }/home/home">首页</a></li>
			<li class="active">系统管理</li>
			<li class="active">管理</li>
		</ul>
		<!-- .breadcrumb -->
	</div>

	<div class="page-content">
		<div class="page-header">
			<h1>
				菜单管理 <small> <i class="ace-icon fa fa-double-angle-right"></i> 菜单维护
				</small>
				
			</h1>
		</div>
		<!-- /.page-header -->
		<div class="row">
			<div class="col-xs-4">
				<div class="widget-box">
					<div class="widget-header header-color-blue2">
						<h4 class="lighter smaller">菜单</h4>
					</div>
					<div class="widget-body">
						<div class="widget-main padding-8">
							<ul id="deptTree" class="ztree"></ul>
						</div>
					</div>
				</div>
			</div>
			<form id="deptForm" action="${ctx }/menu/update" method="post" class="form-horizontal"> 
			<input type="hidden" id="id" name="id" /> 
				<div class="col-xs-5" style="display: none;" id="deptView">
					<div class="widget-header header-color-blue2"></div>
					<div class="widget-body">
						<div class="widget-main padding-8">
							<div>
								<div class="form-group" id="deptName">
									<label for="inputEmail3" class="col-sm-3 control-label"><b
										class="red">*</b><strong>菜单名称</strong></label>
									<div class="col-sm-5">
										<input type="text" class="form-control validate[required]"
											id="name" name="name">
									</div>
								</div>
								<div class="form-group" id="deptName">
									<label for="inputEmail3" class="col-sm-3 control-label"><strong>菜单图标</strong></label>
									<div class="col-sm-5">
										<input type="text" class="form-control"
											id="icon" name="icon">
									</div>
									<div class="col-sm-2">
											<label for="inputEmail3" class=" control-label">
											<a href="http://fontawesome.io/icons" target="_blank">图标库</a>
											</label>
									</div>
								</div>
								<div class="form-group" id="deptName">
									<label for="inputEmail3" class="col-sm-3 control-label"><b
										class="red">*</b><strong>排序</strong></label>
									<div class="col-sm-5">
										<input type="text" class="form-control validate[required]"
											id="sort" name="sort">
									</div>
								</div>
								<div class="form-group" id="deptName">
									<label for="inputEmail3" class="col-sm-3 control-label"><b
										class="red">*</b><strong>状态</strong></label>
									<div class="col-sm-5">
										<select:option type="status" id="status" name="permissions.status" showValue="false"/>
									</div>
								</div>
								<div class="form-group" id="deptBut">
									<div class="col-sm-11" style="text-align: center;">
										<button type="button" class="btn btn-info btn-sm tooltip-info"
											onclick="subForm()">保存</button>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</form>
		</div>
	</div>
</body>
</html>